<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
            body {
                background-color: white;
            }
        </style>
    </head>
    <body>
        <button type="button" id="light">开关灯</button>
        <script type="text/javascript">
            var btn = document.querySelector('#light');
            var body = document.querySelector('body');
            var flag = 0;
            btn.onclick = function() {
                if (flag == 0) {
                    body.style.backgroundColor = 'black';
                    flag = 1;
                } else {
                    body.style.backgroundColor = 'white';
                    flag = 0;
                }
            }
        </script>
    </body>
</html>
